<?php
/**
 * Created by PhpStorm.
 * User: gakuin
 * Date: 16/8/28
 * Time: 上午10:44
 */
namespace app\models;

use yii\base\Model;

class ResetPwdStep1Form extends Model{

    public $username;
    public $code;

    public function rules()
    {
        return [
            ['username', 'required','message'=>'用户名不能为空'],
            ['username','correct']
        ];
    }

    public function attributeLabels()
    {
        return [
            'username' =>'用户名或手机号',
        ];
    }

    public function correct($attribute,$params){
        $user = User::find()->where(['or',"username = '$this->username'","mobile = '$this->username'"])->one();
        if($user == null){
            $this->addError($attribute,'用户名或手机号不存在,请重新输入');
        }
    }
}